﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model CubicFWNet.Data.Models.Technology
@{
    //ViewBag.Title = "核算";
    var product = ViewBag.Product as Product;
    var material = ViewBag.Material as Product;
    var listPro = ViewBag.listPro as List<Product>;
    var orderProduct = ViewBag.OrderProduct as OrderProduct;
    var technologyManage = ViewBag.TechnologyManage as TechnologyManageView;
    var equipment = ViewBag.Equipment as Equipment;
    var techType = ViewBag.TechType as TechType;


    var tnumber = ViewBag.Number;//
                                 //var materialId = ViewBag.MaterialId;
                                 //var productId = ViewBag.ProductId;
                                 //var pName = ViewBag.ProductName;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
}
<section class="content-header">
    <h1>
        工艺成本核算
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        @*<li class="active"><a href="@Url.Action("IndexItem", "Technology", new {tId = Model.Id, pId = productId, pname = pName})">工艺审核</a></li>*@
        <li class="active"><a href="@Url.Action("Index", "Technology")">工艺核算</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (product != null && orderProduct != null && technologyManage != null && material != null && techType != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("Add", "Technology")" method="post">
                        <input type="hidden" id="GmIdNum" name="GmIdNum" value="@techType.ExamineNum" />
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="OrderProductId" name="OrderProductId" value="@Model.OrderProductId" />
                        <input type="hidden" id="CreateTime" name="CreateTime" value="@Model.CreateTime" />
                        <input type="hidden" id="ApplyTime" name="ApplyTime" value="@Model.ApplyTime" />
                        <input type="hidden" id="Status" name="Status" value="@Model.Status" />
                        <input type="hidden" id="ProductID" name="ProductID" value="@orderProduct.ProductId" />
                        <input type="hidden" id="MaterialId" name="MaterialId" value="@material.Id" />
                        <input type="hidden" id="OrderId" name="OrderId" value="@orderProduct.OrderId" />
                        <input type="hidden" id="UserId" name="UserId" value="@Model.UserId" />


                        <input type="hidden" id="EquipmentType" name="EquipmentType" value="@equipment.Id" />
                        <input type="hidden" id="TechType" name="TechType" value="@techType.TechTypeId" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label for="ProductName" class="col-sm-3 control-label">产品名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ProductName" name="ProductName" value="@product.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Pack" class="col-sm-3 control-label">主料名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@material.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Number" class="col-sm-3 control-label">工艺单编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" placeholder="" value="@tnumber" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="Pack" class="col-sm-3 control-label">基本单位</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Pack" name="Pack" value="@product.Pack" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="SizeWidth" class="col-sm-3 control-label">尺寸宽-mm</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeWidth" name="SizeWidth" value="@product.SizeWidth" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="SizeLenth" class="col-sm-3 control-label">尺寸长-mm</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SizeLenth" name="SizeLenth" value="@product.SizeLenth" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control okeydown" data-des="数量" id="Amount" name="Amount" value="@orderProduct.Amount" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label for="SizeLenth" class="col-sm-3 control-label">分配类型</label>
                                <div class="col-sm-9">
                                    <select class="form-control" type="select" data-des="分配类型" id="DistributeType" name="DistributeType">
                                        <option value="1">内部生产</option>
                                        <option value="2">外购</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            @*外购的话下面隐藏*@
                            <div id="IfDistribute">
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">左右间距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" data-des="左右间距-mm" class="form-control okeydown calculate" id="Space" name="Space" value="@product.Space" required>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">左右边距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" data-des="左右边距-mm" class="form-control okeydown calculate" id="Margin" name="Margin" value="@product.Margin" required>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">跳距-mm</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control okeydown calculate" data-des="跳距-mm" id="Distance" name="Distance" value="@product.Distance" required>
                                    </div>
                                </div>


                                <div class="form-group col-md-12" style="height: 1px;"></div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">给定用料长-mm</label>
                                    <div class="col-sm-9">
                                        <label class="control-label" style="color: red">(尺寸长 + 跳距) * (数量 / 刀模数[左右])/1000</label>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">给定用料宽-mm</label>
                                    <div class="col-sm-9">
                                        <label class="control-label" style="color: red">尺寸宽 * 刀模数[左右] + (刀模数[左右] - 1) * 左右间距 + 左右边距 * 2 +15</label>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">生产工时</label>
                                    <div class="col-sm-9">
                                        <label class="control-label" style="color: red">(数量 / (刀模数[左右] * 刀模数[排])) / 设备频率-分钟+调机时间</label>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">检验工时</label>
                                    <div class="col-sm-9">
                                        <label class="control-label" style="color: red">数量 / 检验频率-分钟</label>
                                    </div>
                                </div>
                                <div class="form-group col-md-12" style="height: 1px;"></div>
                                <div id="json-content">
                                    <div id="data-content">
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">设备</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="设备" class="form-control" id="EquipmentTypeName" name="EquipmentTypeName" value="@equipment.EquipmentName" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">类别</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="类别" class="form-control" id="TechTypeName" name="TechTypeName" value="@techType.TechTypeName" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">刀模数[左右]</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="刀模数[左右]" class="form-control okeydown calculate" id="Ch" name="Ch" value="1" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">刀模数[排]</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="刀模数[排]" class="form-control okeydown calculate" id="Cv" name="Cv" value="1" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">长度浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="长度浪费比" class="form-control okeydown calculate" id="WasteHReal" name="WasteHReal" value="1" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">设备频率-分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="频率-分钟" class="form-control" id="MinuteNum" name="MinuteNum" value="@techType.MinuteNum" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">检验频率-分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" data-des="检验频率-分钟" class="form-control" id="JianyanNum" name="JianyanNum" value="@techType.ExamineNum" readonly="readonly">
                                                @*<input type="text" data-des="设备总次数" class="form-control" id="MinuteNumAmount" name="MinuteNumAmount" value="" readonly="readonly">*@
                                            </div>
                                        </div>

                                    </div>
                                    <div class="form-group col-md-12" style="height: 1px;"></div>
                                    <div id="other-content">
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">给定用料宽-mm</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" data-des="给定用料宽-mm" id="GiveW" name="GiveW" maxlength="14" value="" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">给定用料长-m</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" data-des="给定用料长-m" id="GiveH" name="GiveH" maxlength="14" value="" readonly="readonly">
                                            </div>
                                        </div>

                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">原材料浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" data-des="原材料浪费比" id="WasteOri" name="WasteOri" value="" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">允许浪费上限</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" data-des="允许浪费上限" id="WasteOver" name="WasteOver" value="@techType.WasteW" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">宽度浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" data-des="宽度浪费比" id="WasteW" name="WasteW" value="" readonly="readonly">
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">长度浪费比</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" data-des="长度浪费比" id="WasteH" name="WasteH" value="" readonly="readonly">
                                            </div>
                                        </div>
                                        @*<div class="form-group col-md-6">
                                                <label class="col-sm-3 control-label">浪费差异</label>
                                                <div class="col-sm-9">
                                                    <input type="text" class="form-control" data-des="浪费差异" id="WasteDif" name="WasteDif" value="0" readonly="readonly">
                                                </div>
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label class="col-sm-3 control-label">材料直接成本</label>
                                                <div class="col-sm-9">
                                                    <input type="text" class="form-control" data-des="材料直接成本" id="MaterialCost" name="MaterialCost" value="" readonly="readonly">
                                                </div>
                                            </div>*@
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">生产人数</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown sunshu" data-des="生产人数" id="WorkersNum" name="WorkersNum" maxlength="14" value="1" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">生产工时-分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" data-des="生产工时-分钟" id="WorkLenth" name="WorkLenth" value="" maxlength="14" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">检验人数</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown sunshu" data-des="人员数量" id="CheckNum" name="CheckNum" maxlength="14" value="1" required>
                                            </div>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">检验工时-分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" data-des="检验工时-分钟" id="CheckLenth" name="CheckLenth" value="" maxlength="14" required>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div id="wgdisplay" class="hidden">
                                @*<div class="form-group col-md-6">
                                        <label class="col-sm-3 control-label">检验人数</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des="人员数量" id="CheckNumwg" maxlength="14" value="1" required>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-6">
                                        <label class="col-sm-3 control-label">检验工时-分钟</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des="检验工时-分钟" id="CheckLenthwg" value="" maxlength="14" readonly="readonly">
                                        </div>
                                    </div>*@
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div id="listPro-content">
                                @if (listPro != null)
                                {
                                    foreach (var item in listPro)
                                    {
                                        <div class="listProItem-content">
                                            <div class="form-group col-md-6">
                                                <label for="ProductName" class="col-sm-3 control-label">辅料名称</label>
                                                <div class="col-sm-9">
                                                    <input type="text" class="form-control" name="MaterialName" value="@item.Name" readonly="readonly">
                                                    <input type="hidden" class="form-control" id="MaterialId" name="MaterialId" value="@item.Id">
                                                </div>
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label for="ProductName" class="col-sm-3 control-label">辅料数量</label>
                                                <div class="col-sm-9">
                                                    <input type="text" class="form-control okeydown" id="Count" name="Count" value="" required>
                                                </div>
                                            </div>
                                        </div>
                                    }
                                }
                            </div>
                            @*<div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">辅料说明</label>
                                    <div class="col-sm-9">
                                        <textarea class="form-control" rows="3" placeholder="请输入 ..." name="HelpMemo" id="HelpMemo" required></textarea>
                                    </div>
                                </div>
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">辅料总价</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control okeydown" data-des="辅料总价" id="HelpMoney" name="HelpMoney" maxlength="14" value="" required>
                                    </div>
                                </div>*@
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Memo" id="Memo"></textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            <a role="button" id="submitId" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">审核完成</a>
                            @*<a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(3)">拒审</a>*@
                            <a class="btn btn-primary submitbtn" href="@Url.Action("Index", "Technology")">返回</a>
                            @*<a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(2)">外购</a>*@
                            <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：采购管理-->原料成本核算</div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<!--添加原材料对话框-->
@*<div class="modal" id="editDlg" style="display: none">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">添加原材料</h4>
                </div>
                <div class="modal-body">
                    <div id="permissionTree"></div>
                </div>
                <div class="modal-footer">
                    <a role="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</a>
                    <a role="button" class="btn btn-primary" id="add">添加</a>
                </div>
            </div>
        </div>
    </div>*@

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    $("#submitId").attr('disabled', "true");
                    var postData = $(form).formSerialize();
                    postData.Data = getParam();//JSON.stringify(postData._Data);
                    postData.TechnologyMemo = getParamTe();
                    postData.technologyItemList = getParamMaterials();
                    postData.Type = type;
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("Index", "Technology")';
                        }
                    });
                }
            });

            calculate();
            calculateLenth();
            //var yy = document.getElementById("modalData").value;
            //if (yy != "") {
            //    var data = JSON.parse(document.getElementById("modalData").value);
            //    var $content = $('#data-content');
            //    var html = "";
            //    data.forEach(function (e, i) {
            //        if (typeof e.value == "undefined") {
            //            e.value = "";
            //        }
            //        if (typeof e.name == "undefined") {
            //            e.name = "";
            //        }
            //        if (typeof e.des == "undefined") {
            //            e.des = "未知";
            //        }
            //        html += "<div class='form-group col-md-6'>";
            //        html += "<label for='j_a' class='col-sm-3 control-label'>" + e.des + "</label>";
            //        html += "<div class='col-sm-9'>";
            //        html += "<input type='text' class='form-control' id='" + e.name + "' name='" + e.name + "' value='" + e.value + "' readonly='readonly'>";
            //        html += "</div></div>";
            //    });
            //    $content.append(html);
            //}
        });


        var type = 1;
        function formsubmit(t) {
            var distributeType = $("#DistributeType").val();
            if (distributeType == "1") {
                var wasteHReal = $("#WasteHReal").val(); //长度浪费比()
                var WasteH = $("#WasteH").val(); //长度浪费比()
                
                var wasteOver = $("#WasteOver").val();//允许浪费上限
                var wasteOri = $("#WasteOri").val();//原材料浪费比

                if (wasteOri > 1) {
                    $.modalAlert("给定用料不够", "warning");
                    return false;
                }
                if (wasteOver != "" && (wasteOri / 1) > (wasteOver / 1)) {
                    $.modalAlert("原材料浪费比已经大于允许浪费上限比", "warning");
                    return false;
                }
                if (isNaN(wasteHReal) || wasteHReal == 0) {
                    $.modalAlert("长度浪费比填写有误", "warning");
                    return false;
                }
                if (isNaN(WasteH)) {
                    $.modalAlert("长度浪费计算结果有误", "warning");
                    return false;
                }
            }
            type = t;

            $("#frmedit").submit();
        }
        function getParam() {
            var postdata = [];
            //主键
            $("#other-content").find('input,select,textarea').each(function (r) {
                var $this = $(this);
                var id = $this.attr('id');
                var type = $this.attr('type');
                if (id) {
                    switch (type) {
                        case "checkbox":
                            postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
                            break;
                        case "select":
                            var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                        default:
                            var value = $this.val() == "" ? "&nbsp;" : $this.val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                    }
                }
            });
            return JSON.stringify(postdata);
        }
        function getParamTe() {
            var postdata = [];
            //主键
            $("#data-content").find('input,select,textarea').each(function (r) {
                var $this = $(this);
                var id = $this.attr('id');
                var type = $this.attr('type');
                if (id) {
                    switch (type) {
                        case "checkbox":
                            postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
                            break;
                        case "select":
                            var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                        default:
                            var value = $this.val() == "" ? "&nbsp;" : $this.val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                    }
                }
            });
            return JSON.stringify(postdata);
        }

        function getParamMaterials() {
            var postdata = [];
            //主键
            $("#listPro-content").find('.listProItem-content').each(function (r, i) {
                var technologyItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var id = $this.attr('id');
                    if (id) {
                        var value = $this.val() == "" ? "&nbsp;" : $this.val();
                        technologyItem[id] = value;
                    }
                });
                postdata.push(technologyItem);
            });
            return postdata;
            //return JSON.stringify(postdata);
        }

        function calculate() {
            var sizeWidth = $("#SizeWidth").val() / 1; //尺寸宽-mm
            var sizeLenth = $("#SizeLenth").val() / 1; //尺寸长-mm
            var wasteHReal = $("#WasteHReal").val(); //长度浪费比()
            var space = $("#Space").val() / 1; //左右间距-mm
            var margin = $("#Margin").val() / 1; //左右边距-mm
            var distance = $("#Distance").val() / 1; //跳距-mm
            var minuteNum = $("#MinuteNum").val() / 1; //产量-分钟
            var wasteOver = $("#WasteOver").val() / 1; //允许浪费上限
            var amount = $("#Amount").val() / 1;//数量
            var ch = $("#Ch").val() / 1;//刀模数[左右]
            var cv = $("#Cv").val() / 1;//刀模数[排]
            if (ch <= 0) {
                ch = 0;
            }
            if (isNaN(wasteHReal) || wasteHReal == "") {
                wasteHReal = 0;
            } else {
                wasteHReal = wasteHReal / 1;
            }

            var giveW = sizeWidth * ch + (ch - 1) * space + margin * 2 + 15;//给定用料宽-mm
            //var giveW = sizeWidth * ch + (ch - 1) * space + 15;//给定用料宽-mm
            var comH = amount / ch;
            var giveH = (sizeLenth + distance) * comH;//给定用料长-mm
            giveH = giveH * (wasteHReal);
            
            var wasteOri = (sizeWidth * sizeLenth) / (giveW * giveH);//原材料浪费比
            var wasteW = 1 - (sizeWidth / (giveW * ch));//宽度浪费比
            var wasteH = 1 - (sizeLenth / (giveH * cv));//长度浪费比

            $("#GiveW").val(giveW.toFixed(2));
            $("#GiveH").val((giveH / 1000).toFixed(2));
            $("#WasteOri").val(wasteOri.toFixed(2));
            $("#WasteW").val(wasteW.toFixed(2));
            $("#WasteH").val(wasteH.toFixed(2));

            //if (isNaN(j_a) || j_a == "" || j_a == "Infinity" || j_a == "NaN") {
            //    $("#j_a").val("");
            //    return;
            //}
        }

        $(".sunshu").keyup(function () {
            calculateLenth();
        });
        function calculateLenth() {
            var amount = $("#Amount").val() / 1;//数量
            var workersNum = $("#WorkersNum").val() / 1;//生产人数
            var checkNum = $("#CheckNum").val() / 1;//检验人数
            var minuteNum = $("#MinuteNum").val() / 1; //设备产量-分钟
            var ch = $("#Ch").val() / 1;//刀模数[左右]
            var cv = $("#Cv").val() / 1;//刀模数[排]
            var gmIdNum = $("#GmIdNum").val() / 1;//类别对应的检验 检验产量/分钟
            if (gmIdNum == 0) {
                gmIdNum = 1;
            }
            if (workersNum == "" || isNaN(workersNum) || workersNum == "Infinity" || workersNum == "NaN") {
                workersNum = 1;
            }
            if (isNaN(minuteNum) || minuteNum == "" || minuteNum == 0) {
                minuteNum = 1;
            }
            if (ch <= 0) {
                ch = 0.1;
            }
            if (cv <= 0) {
                cv = 0.1;
            }

            var gg = Math.ceil(amount / (ch * cv));
            var workLenth = (gg / minuteNum) / workersNum;
            if (workLenth.toFixed(2) <= 0) {
                workLenth = 0.1;
            }
            var checkLenth = (amount / gmIdNum) / checkNum;
            if (checkLenth.toFixed(2) <= 0) {
                checkLenth = 0.1;
            }
            //$("#MinuteNumAmount").val(gg);
            $("#WorkLenth").val(workLenth.toFixed(0));//生产工时-分钟
            $("#CheckLenth").val(checkLenth.toFixed(0));//检验工时-分钟

            $("#CheckLenthwg").val(checkLenth.toFixed(0));//检验工时-分钟
        }

        $("#DistributeType").on("change", function () {
            var value = $(this).val();
            if (value == "2") {
                $("#IfDistribute").addClass("hidden");
                $("#wgdisplay").removeClass("hidden");
            } else {
                $("#IfDistribute").removeClass("hidden");
                $("#wgdisplay").addClass("hidden");
            }
        });

        $(".calculate").keyup(function () {
            var val = $(this).val();
            if (isNaN(val) || val == "" || val == "Infinity" || val == "NaN" || (val / 1) < 0) {
                $(this).val(0);
            }
            calculate();
            calculateLenth();
        });

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });


        @*//确认添加原材料
        $("#add").click(function () {
            var a = String($("#permissionTree").getCheckedNodesValue());
            var b = String($("#permissionTree").getCheckedNodes());
            $("#treespan").text(a);
            $("#Materials").val(b);
            $('#editDlg').modal("hide");
        });
        function initControl() {
            $("#permissionTree").treeview({
                height: 300,
                showcheck: true,
                url: "@Url.Action("GetPermissionTree", "Technology")"
            });
        }
        //显示原材料弹出框
        function create() {
            initControl();
            $('#editDlg').modal();
        }*@
    </script>
}